import {Navigate} from "react-router-dom";
import {useLocation} from "react-router-dom";
import {ReactNode} from "react";
interface Iprops {
    children?: ReactNode
}

function Private(props: Iprops) {
    var token = sessionStorage.getItem("token")
    const location = useLocation()
    if (token) {
        return <>{props.children}</>
    } else {
        return <Navigate to={{pathname: "/", search: "?redirect=" + location.pathname}}></Navigate>
    }
}

export default Private;
